<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>1_类的基本知识</title>
</head>
<body>
    <script type="text/javascript">

        class Person{
            constructor(name,age){
                this.name = name;
                this.age = age;
            }

            //一般方法
            speak(){
                console.log(`我叫${this.name},年龄是${this.age}`);
            }
        }

       
        //创建一个Person的实例对象
        // const p1 = new Person('tom',18);
        // const p2 = new Person('jerry',19);
        // console.log(p1)
        // console.log(p2)
        // p1.speak()
        // p2.speak()

        //创建一个student类 继承于person
        class Student extends Person{
            constructor(name,age,grade){
                super(name,age);
                this.grade=grade;
            }

            //重写父类方法
            speak(){
                console.log(`我叫${this.name},年龄是${this.age},我读的是${this.grade}`);
            }

            study(){
                console.log("我很努力的学习")
            }
        }

        const s1 = new Student('tom','12','高一')
        console.log(s1);
        s1.speak();
        s1.study();
    </script>
    
</body>
</html>